#!/bin/bash

# 创建临时容器（不运行）,复制出来配置目录和html目录
container_id=$(docker create nginx)

# 检查是否成功创建容器
if [ -z "$container_id" ]; then
    echo "无法创建容器，请确保Docker已运行且有权访问。"
    exit 1
fi

# 复制配置和HTML文件
echo "正在复制Nginx配置文件..."
docker cp "$container_id:/etc/nginx" ./nginx 2>/dev/null || {
    echo "复制配置失败，删除临时容器..."
    docker rm -v "$container_id" >/dev/null
    exit 1
}

echo "正在复制HTML文件..."
docker cp "$container_id:/usr/share/nginx/html" ./html 2>/dev/null || {
    echo "复制HTML失败，删除临时容器..."
    docker rm -v "$container_id" >/dev/null
    exit 1
}

# 删除临时容器
docker rm -v "$container_id" >/dev/null
echo "操作完成！配置文件已保存到当前目录的nginx/和html/文件夹中。"

# 复制模版
curl -O https://gitee.com/iicode/my_sharecode/raw/master/docker/nginx_docker-compose.yml